package com.yh.threadTest.task;

/**
 * @ClassName Test
 * @Description TODO
 * @Author 0715-YuHao
 * @Date 2020/11/14 13:51
 */
public class Test {

    private volatile Boolean flag;

    public static void main(String[] args) {

        Thread A = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "开始执行");
            for (int i = 0; i < 10; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "正在执行。。。");
            }
            System.out.println(Thread.currentThread().getName() + "执行完成");
        }, "A");
        Thread B = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "开始执行");
            for (int i = 0; i < 12; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "正在执行。。。");
            }
            System.out.println(Thread.currentThread().getName() + "执行完成");
        }, "B");
        Thread C = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "开始执行");
            for (int i = 0; i < 8; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "正在执行。。。");
            }
            System.out.println(Thread.currentThread().getName() + "执行完成");
        }, "C");
        Thread D = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "开始执行");
            for (int i = 0; i < 7; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "正在执行。。。");
            }
            System.out.println(Thread.currentThread().getName() + "执行完成");
        }, "D");
        Thread E = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "开始执行");
            for (int i = 0; i < 2; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println(Thread.currentThread().getName() + "执行完成");
        }, "E");

        A.start();
        B.start();
        C.start();
        D.start();

        Thread.State state = B.getState();

        while (B.isAlive()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        E.start();
    }

}
